<template>
  <div class="box">
    <div class="descriptions">
      <div class="user-title-box">造价单信息</div>
      <el-descriptions :column="4" border>
        <el-descriptions-item label="预计开工日期">{{ hisQuotationData.start_date || "--"
          }}</el-descriptions-item>
        <el-descriptions-item label="预计完工日期">{{ hisQuotationData.end_date || "--"
          }}</el-descriptions-item>
        <el-descriptions-item label="预计工期">{{
          hisQuotationData.duration_days
            ? hisQuotationData.duration_days + "天"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="建筑面积">{{
          hisQuotationData.building_area
            ? hisQuotationData.building_area + "m²"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="基础装修费">{{
          hisQuotationData.basic_decoration_fee
            ? hisQuotationData.basic_decoration_fee + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="主材采购费用">{{
          hisQuotationData.material_costs
            ? hisQuotationData.material_costs + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="报价税金">{{
          hisQuotationData.quotation_taxes
            ? hisQuotationData.quotation_taxes + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="现场采购成本">{{
          hisQuotationData.procurement_cost
            ? hisQuotationData.procurement_cost + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="公司集采成本">{{
          hisQuotationData.centralized_procurement_cost
            ? hisQuotationData.centralized_procurement_cost + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="管理成本">{{
          hisQuotationData.management_costs
            ? hisQuotationData.management_costs + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="报价金额">{{
          hisQuotationData.quotation_amount
            ? hisQuotationData.quotation_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="成本金额">{{
          hisQuotationData.cost_amount
            ? hisQuotationData.cost_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="利润金额">{{
          hisQuotationData.profit_amount
            ? hisQuotationData.profit_amount + "元"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="利润率(报价)">{{
          hisQuotationData.profit_ratio
            ? hisQuotationData.profit_ratio + "%"
            : "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="报价类型">
          <template v-if="hisQuotationData.quotation_type == 1">基础施工报价（首次）</template>
          <template v-if="hisQuotationData.quotation_type == 2">基础施工报价（调整）</template>
          <template v-if="hisQuotationData.quotation_type == 3">增减项施工报价</template>
        </el-descriptions-item>
        <el-descriptions-item label="备注" v-if="hisQuotationData.remark">{{
          hisQuotationData.remark || "--"
        }}</el-descriptions-item>
        <el-descriptions-item label="报价单文件" :span="2">
          <div class="file-box-img-box flex ac">
            <div class="file-box-img" v-for="(item, idx) in hisQuotationData.quotation_file" :key="idx">
              <el-tooltip class="item" effect="dark" :content="item.file_name" placement="top">
                <img class="img" :src="$fileImgFunc(item)" @click="$fileViewHandle(item)" />
              </el-tooltip>
            </div>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="利润单文件" :span="2">
          <div class="file-box-img-box flex ac">
            <div class="file-box-img" v-for="(item, idx) in hisQuotationData.profit_statement_file" :key="idx">
              <el-tooltip class="item" effect="dark" :content="item.file_name" placement="top">
                <img class="img" :src="$fileImgFunc(item)" @click="$fileViewHandle(item)" />
              </el-tooltip>
            </div>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="工程量清单" :span="2">
          <div class="file-box-img-box flex ac">
            <div class="file-box-img" v-for="(item, idx) in hisQuotationData.cost_list_file" :key="idx">
              <el-tooltip class="item" effect="dark" :content="item.file_name" placement="top">
                <img class="img" :src="$fileImgFunc(item)" @click="$fileViewHandle(item)" />
              </el-tooltip>
            </div>
          </div>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <div class="descriptions">
      <div class="user-title-box">审核操作</div>
      <el-form :model="shbjdRuleForm" :rules="shbjdRules" ref="shbjdRuleForm" label-position="top">
        <el-form-item label="" prop="reviewPassed">
          <el-radio-group v-model="shbjdRuleForm.reviewPassed" size="small">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="shbjdRuleForm.reviewPassed == 1 ? '备注' : '理由'" prop="remark">
          <el-input :rows="4" class="input-box" v-model="shbjdRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="shbjdSubmit('shbjdRuleForm')" :disabled="diaLoading"
          :loading="diaLoading">提交</el-button>
        <el-button @click="shbjdCancel('shbjdRuleForm')">关闭</el-button>
      </span>
    </div>
  </div>
</template>
<script>
import projectApi from "@/api/projectApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";

export default {
  name: "shbjdCom",
  data() {
    return {
      shbjdRules: {},
      shbjdRuleForm: {
        remark: "",
        quotation_id: "",
        reviewPassed: 1,
      },
      diaLoading: false,
      hisQuotationData: "",
    };
  },

  computed: {},
  mounted() {
    this.project_id = this.$route.query.id;
    this.getProjectLog();
  },
  methods: {
    // 审核报价单
    shbjdCancel(formName) {
      this.$goBackTab(this);
    },
    shbjdSubmit(formName) {
      let shbjdRuleForm = this.shbjdRuleForm;
      console.log(shbjdRuleForm, "审核报价单参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          // 拒绝
          if (shbjdRuleForm.reviewPassed == 2) {
            projectApi
              .quotationReviewRejected({
                quotation_id: "",
                project_id: this.project_id,
                remark: shbjdRuleForm.remark,
              })
              .then((res) => {
                console.log(res, "审核报价单");
                this.diaLoading = false;
                if (res.code == 200) {
                  this.shbjdCancel();
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          // 通过
          projectApi
            .quotationReviewPassed({
              quotation_id: "",
              project_id: this.project_id,
              remark: shbjdRuleForm.remark,
              audit_type: 2
            })
            .then((res) => {
              console.log(res, "审核报价单");
              this.diaLoading = false;
              if (res.code == 200) {
                this.shbjdCancel();
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 获取项目日志
    getProjectLog() {
      this.logList = [];
      this.logLoaidng = true;
      projectApi
        .getProjectLogList({
          project_id: this.$route.query.id,
          log_type: 0,
        })
        .then((res) => {
          console.log(res, "项目日志");
          this.logLoaidng = false;
          if (res.code == 200) {
            res.data.forEach((item) => {
              if (item.form_data) {
                item.form_data = JSON.parse(item.form_data);
              }
              // 拿到最近一条历史造价单（再次造价时用,审核用）
              if (item.log_status == 220 && !this.hisQuotationData) {
                this.hisQuotationData = item.form_data;
              }
            });
          }
        })
        .catch((err) => {
          this.logLoaidng = false;
        });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/shPage.scss";
</style>